﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestGUI
{

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        SerialPort port;
        byte[] buffer;

        public MainWindow()
        {
            port = new SerialPort("COM4", 115200);
            port.Open();
            port.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
            InitializeComponent();
        }

        private void ComboBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            buffer = new byte[] { 2, 4, 1, 1, 222, (byte)((ComboBox)sender).SelectedIndex };
            port.Write(buffer, 0, buffer.Length);
            
        }

        private void ComboBox_SelectionChanged_2(object sender, SelectionChangedEventArgs e)
        {
            buffer = new byte[] { 2, 4, 1, 1, 223, (byte)((ComboBox) sender).SelectedIndex };
            port.Write(buffer, 0, buffer.Length);
        }

        public void DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Console.Write(port.ReadByte());
        }

    }
}
